package com.emptyMe.org.service.impl;

import com.emptyMe.org.domain.Goods;
import com.emptyMe.org.domain.Size;
import com.emptyMe.org.domain.Type;
import com.emptyMe.org.mapper.GoodsMapper;
import com.emptyMe.org.query.GoodsQuery;
import com.emptyMe.org.service.IGoodsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)

public class GoodsImpl implements IGoodsService {
    @Resource
    private GoodsMapper mapper;

    @Override
    @Transactional
    public void SaveGood(Goods goods) {
        if(goods.getId()!=null){
           mapper.updateGood(goods);
        }else{
            mapper.AddGood(goods);
        }
    }

    @Override
    public PageInfo<Goods> findAllGood(GoodsQuery query) {
        PageHelper.startPage(query.getCurrentPage(),query.getPageSize());
        List<Goods> list = mapper.findAllGood(query);
        Page<Goods> page = (Page<Goods>) list;
        return page.toPageInfo();
    }

    @Override
    @Transactional
    public void DelGood(List<Long> id) {
        mapper.delGood(id);
    }

    @Override
    public List<Type> findType() {
        return mapper.findType();
    }

    @Override
    public List<Size> findSize(Long goodId) {
        return mapper.findSize(goodId);
    }

    @Override
    public Integer sumNum(Long id) {
        return mapper.sumNum(id);
    }
}
